package com.servlet;

import com.entity.Students;
import com.tools.Utils;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class SelectOne {
    //Update的单条Select执行方法，详见SelectALl类
    public  Students getOne(Integer sid) {
        Connection conn = Utils.getConn();
        Students stu = new Students();
        try {
            Statement statement = conn.createStatement();
            ResultSet resultSet = statement.executeQuery("SELECT * FROM students WHERE Sid=" + sid + ";");
            if (resultSet.next()) {
                stu.setSid(resultSet.getInt("Sid"));
                stu.setSname(resultSet.getString("Sname"));
                stu.setSage(resultSet.getString("Sage"));
                stu.setSclass(resultSet.getString("Sclass"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return stu;
    }
}
